﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using UncleBobWebService.Models;
using UncleBobWebService.ServiceRequester;
using UncleBobWebService.Database;

namespace UncleBobApplicantWebService.Controllers
{
    public class JobListQuestionsController : Controller
    {
        private UncleBobApplicantWebService.ApplicantWebService.WebServiceClient m_applicantClient =
            new UncleBobApplicantWebService.ApplicantWebService.WebServiceClient();
        //
        // GET: /JobListQuestions/
        private JobModel job = new JobModel();

        public ActionResult JobListQuestionsView()
        {
            job = Session[SessionKeys.JOB] as JobModel;

            Message msg = new Message(MessageTypes.SERVICE_GET_JOB_QUESTIONS);
            msg = new Message(MessageTypes.SERVICE_GET_JOB_QUESTIONS);
            msg.Data = job;
            msg = m_applicantClient.RequestService(msg);

            job.QuestionsList = msg.Data as ApplicationQuestions;

            return View(job);
        }

        public ActionResult FormAction(FormCollection collection)
        {
            if (collection.Get("submit") != null)
            {
                Message msg = new Message(MessageTypes.SERVICE_GET_JOB_QUESTION);
                msg.Data = collection["answer"];
                msg = m_applicantClient.RequestService(msg);
                Session.Add(SessionKeys.QUESTION, msg.Data);
                return RedirectToAction("EditQuestion", "EditQuestion");
            }          

            return RedirectToAction("QuestionsMenu", "QuestionsMenu");
        }

    }
}
